package com.homer.gps.track.persist;

import com.j256.ormlite.dao.ForeignCollection;
import com.j256.ormlite.field.DatabaseField;
import com.j256.ormlite.field.ForeignCollectionField;
import com.j256.ormlite.table.DatabaseTable;

@DatabaseTable(tableName = "routes")
public class RouteModel {
	
	public final static String ID_FIELD_NAME = "id";

	@DatabaseField(generatedId = true, columnName = ID_FIELD_NAME)
	private int id;

	@DatabaseField(canBeNull = false)
	private String name;
	
	@DatabaseField(canBeNull = false)
	private int type;
	
	@DatabaseField(canBeNull = false)
	private boolean running;
	
	@DatabaseField(canBeNull = true)
	private String note;

	@ForeignCollectionField
	private ForeignCollection<PointModel> points;
	
	@ForeignCollectionField
	private ForeignCollection<StopModel> stops;

	public RouteModel() {
		// all persisted classes must define a no-arg constructor with at least package visibility
	}

	public ForeignCollection<PointModel> getPoints() {
		return this.points;
	}
	
	public ForeignCollection<StopModel> getStops() {
		return this.stops;
	}

	public int getId() {
		return this.id;
	}

	public String getName() {
		return this.name;
	}

	public void setId(final int id) {
		this.id = id;
	}

	public void setName(final String name) {
		this.name = name;
	}

	public int getType() {
		return type;
	}

	public void setType(int type) {
		this.type = type;
	}

	public final boolean hasId() {
		return 0 != this.id;
	}

	public boolean isRunning() {
		return running;
	}

	public void toggleRunning() {
		this.running = !this.running;
	}

	public void setRunning(boolean running) {
		this.running = running;
	}

	public String getNote() {
		return note;
	}

	public void setNote(String note) {
		this.note = note;
	}
}
